package cn.stylefeng.guns.cp;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alipay.api.domain.Person;
import lombok.Data;
import lombok.SneakyThrows;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Description TODO
 * @Author xiesm
 * @Date 2023/12/21 11:09
 **/
@Data
public class Sc10 implements Comparable<Sc10> {
    private String issue;
    private String code1;
    private String code2;
    private String code3;
    private String code4;
    private String code5;
    private String code6;
    private String code7;
    private String code8;
    private String code9;
    private String code10;

    public Sc10(String issue, String... codes) {
        this.issue = issue;
        this.code1 = codes[0];
        this.code2 = codes[1];
        this.code3 = codes[2];
        this.code4 = codes[3];
        this.code5 = codes[4];
        this.code6 = codes[5];
        this.code7 = codes[6];
        this.code8 = codes[7];
        this.code9 = codes[8];
        this.code10 = codes[9];
    }

    public Sc10(List<Object> codes) {
        this.issue = codes.get(0).toString();
        this.code1 = codes.get(1).toString();
        this.code2 = codes.get(2).toString();
        this.code3 = codes.get(3).toString();
        this.code4 = codes.get(4).toString();
        this.code5 = codes.get(5).toString();
        this.code6 = codes.get(6).toString();
        this.code7 = codes.get(7).toString();
        this.code8 = codes.get(8).toString();
        this.code9 = codes.get(9).toString();
        this.code10 = codes.get(10).toString();
    }

    public Sc10(String issue, List<Object> codes) {
        this.issue = issue;
        this.code1 = codes.get(0).toString();
        this.code2 = codes.get(1).toString();
        this.code3 = codes.get(2).toString();
        this.code4 = codes.get(3).toString();
        this.code5 = codes.get(4).toString();
        this.code6 = codes.get(5).toString();
        this.code7 = codes.get(6).toString();
        this.code8 = codes.get(7).toString();
        this.code9 = codes.get(8).toString();
        this.code10 = codes.get(9).toString();
    }

    public String getCodes() {
        return StrUtil.format("{},{},{},{},{},{},{},{},{},{}",
                code1, code2, code3, code4, code5, code6, code7, code8, code9, code10);
    }

    public String getCode(Integer num) {
        String code = null;
        switch (num) {
            case 1:
                code = code1;
                break;
            case 2:
                code = code2;
                break;
            case 3:
                code = code3;
                break;
            case 4:
                code = code4;
                break;
            case 5:
                code = code5;
                break;
            case 6:
                code = code6;
                break;
            case 7:
                code = code7;
                break;
            case 8:
                code = code8;
                break;
            case 9:
                code = code9;
                break;
            case 10:
                code = code10;
                break;
        }
        return code;
    }

    @Override
    public int compareTo(Sc10 o) {
        return o.getIssue().compareTo(this.getIssue());
    }

    public static void addAll(List<Sc10> sc1, List<Sc10> sc2) {
        Set<String> set = new HashSet<>();
        for (int i = 0; i < sc1.size(); i++) {
            Sc10 sc10 = sc1.get(i);
            set.add(sc10.getIssue());
        }
        for (int i = 0; i < sc2.size(); i++) {
            if (set.add(sc2.get(i).getIssue())) {
                sc1.add(sc2.get(i));
            }
        }
    }

    public String getLxCode(int num) {
        String code = null;
        switch (num) {
            case 4:
                code = StrUtil.format("{} {} {} {}", code1, code2, code3, code4);
                break;
            case 5:
                code = StrUtil.format("{} {} {} {} {}", code1, code2, code3, code4, code5);
                break;
        }
        return code;
    }
}
